<?php
function show_post()
{
	if(isset($_GET['message']) && !empty($_GET['message']))
		echo "<font color=red> $_GET[message] </font>";

	else
	{
		// MEnampilkan data yang tersimpan di file
		$file = "do_not_delete_this_file.naldo";
			
		$file_open = fopen($file, 'r');
		
		$output=fgets($file_open);
		$output=explode(';',$output);
		
		$library_sensor=array(":)","jelek","anjing","monyet","sialan","fuck","shit");
		$library_filter=array("<img src=smiley1.jpg>","luar biasa","a**i**","*o**e*","si****","f***","***t");
	
		$indeks = 0;
	
		while(isset($output[$indeks+2]))
		{
			$link = "nama=" . $output[$indeks] . "&email=" . $output[$indeks+1] . "&pesan=" . $output[$indeks+2];
			$output[$indeks] = str_replace($library_sensor,$library_filter,$output[$indeks]);

				echo "nama : " . $output[$indeks] . "<br>";
				echo "email : <a href=mailto:" . $output[$indeks+1] . ">" . $output[$indeks+1] . "</a><br>";
				echo "pesan : " . $output[$indeks+2] . "<br><br>";
				echo "<a href=delpost.php?$link> <button> Delete </button></a><br><br>";
			$indeks+= 3;
		}
	}
}

function write_file()
{
	$file = "do_not_delete_this_file.naldo";
	$file_open = fopen($file, 'a+');
	$input = $_POST['nama'] . ";" . $_POST['email'] . ";" . $_POST['pesan'] . ";";

	if(fwrite($file_open,$input))
		echo "Data Berhasil Disimpan...<br><br>";
	else
		echo "Data Gagal Disimpan...<br><br>";

	fclose($file_open);
}

show_post();
?>
	
<pre>
<form action=index.php method=post>
Nama   : <input type=text name=nama>
E-Mail : <input type=text name=email>
Pesan  : <input type=text name=pesan>
<input type=submit value=kirim>
</form>
</pre>

<?php
		// Menyimpan data ke dalam file
	if(isset($_POST['nama']) && isset($_POST['email']) && isset($_POST['pesan']))
	{
		if(!empty($_POST['nama']) && !empty($_POST['email']) && !empty($_POST['pesan']))
		{
			if(strpos($_POST['email'],'@') && strpos($_POST['email'],'.'))
			{
				write_file();
				header("Location:index.php");
			}
			
			else
			{
				$pesan = "Maaf, Email tidak valid";
				header("Location:index.php?message=$pesan");				
			}
		
		}
		else
		{
			$pesan = "Maaf, Semua form harus diisi dengan benar...";
			header("Location:index.php?message=$pesan");				
		}
	}
?>